﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ImageTesting
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            imgToon.ImageUrl = "http://i1259.photobucket.com/albums/ii542/115david/CevoraLogo.jpg";
        }

        //protected void btnUpload_Click(object sender, EventArgs e)
        //{
        //    int sizeLimit = 5242880;
        //    if (opladen.HasFile)
        //    {
        //        if (opladen.PostedFile.ContentLength <= sizeLimit)
        //        {
        //            string path = @"C:\Upload\" + opladen.FileName;
        //            opladen.SaveAs(path);
        //            lblmsg.Text = "BESTAND OPGELADEN NAAR : " + path;
        //            imgToon.ImageUrl = opladen.PostedFile.FileName;
                    
        //        }
        //        else
        //        {
        //            lblmsg.Text = "BESTAND IS TE GROOT!!!!";
        //        }
        //    }
        //}

        //protected void btnShow_Click(object sender, EventArgs e)
        //{
        //    lblmsg.Text = opladen.PostedFile.FileName;
        //    imgToon.ImageUrl = opladen.PostedFile.FileName;
        //}

        protected void save_btn_Click(object sender, EventArgs e)
        {
            if (uploadfile.PostedFile != null)
            {
                // Check file size 

                HttpPostedFile myFile = uploadfile.PostedFile;
                int nFileLen = myFile.ContentLength;
                if (nFileLen == 0)
                {
                    RequiredFieldValidator1.ErrorMessage = "niets opgeladen";
                    RequiredFieldValidator1.IsValid = false;
                    return;
                }

                // Check file extension (must be JPG)

                if (System.IO.Path.GetExtension(myFile.FileName).ToLower() != ".jpg" && System.IO.Path.GetExtension(myFile.FileName).ToLower() != ".gif" && System.IO.Path.GetExtension(myFile.FileName).ToLower() != ".bmp")
                {

                    RequiredFieldValidator1.ErrorMessage = "JPG of GIF";
                    RequiredFieldValidator1.IsValid = false;
                    return;
                }
                else
                {
                    String FilePath;
                    FilePath = Server.MapPath("/pics");
                    myFile.SaveAs(MapPath(System.IO.Path.GetFileName(myFile.FileName).ToLower().ToString()));
                    string path = @"C:\Upload\" + myFile.FileName;
                    myFile.SaveAs(path);
                    //TOON OPGELADEN TEKENING
                    imgPicture.ImageUrl = System.IO.Path.GetFileName(myFile.FileName).ToLower().ToString();
                }
            }
        }




    }
}
